﻿using System.Net.Mail;
using LogikBug.Async.Tasks;
using LogikBug.Async.Tasks.Entities;

namespace LogikBug.Async.ConsoleApp
{
	public class EmailAgent : Agent<MailMessageModel>
	{
		private SmtpClient client;

		public EmailAgent(MailMessageModel message) : base(message)
		{
		}

		public override void Execute()
		{
			client = new SmtpClient(Model.Host, Model.Port);
			client.Send(Model.Entity);
		}

		protected override void Dispose(bool disposing)
		{
			base.Dispose(disposing);

			if (disposing && client != null)
			{
				client.Dispose();
			}
		}
	}

	public class MailMessageModel : Model<MailMessage>
	{
		public MailMessageModel(MailMessage entity) : base(entity)
		{
		}

		public string Host { get; set; }

		public int Port { get; set; }

		public void InitEntity()
		{
			// Initialize here or before it's passed in.
			Entity.To.Add("email@address.com");
			Entity.Body = "Here is my email";
			Entity.From = new MailAddress("support@domain.com");
		}
	}
}
